package com.shop.front.dao.pink;

import com.shop.jpa.BaseDao;
import com.shop.domain.pink.UserSnapPinkInfo;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

@Repository
public interface UserSnapPinkInfoDao extends BaseDao<UserSnapPinkInfo, Long> {

    @Query("from UserSnapPinkInfo where uid=?1 and pinkId=?2")
    public UserSnapPinkInfo findByPinkIdAndUserId(Long userId, Long pinkId);

    // 增加寄售成功次数
    @Modifying(clearAutomatically = true)
    @Query(value = "update UserSnapPinkInfo set jishouNum = jishouNum + 1 where id = ?1 ")
    int updateByJishouSuccess(Long id);

    // 增加提货成功次数
    @Modifying(clearAutomatically = true)
    @Query(value = "update UserSnapPinkInfo set getGoodsNum = getGoodsNum + 1 where uid = ?1 and pinkId = ?2 ")
    int updateByGetGoods(Long userId, Long pinkId);


    //修改拼团配置
    @Modifying(clearAutomatically = true)
    @Query(value = "update UserSnapPinkInfo set isAutoPt = ?6,autoProductId = ?3,autoProductAttrValueId = ?4 , autoAddressId = ?5, updateTime = now() where uid = ?1 and pinkId = ?2 ")
    int updateStorePinkConfig(Long userId,Long pinkId,Long productId,Long productAttrValueId,Long userAddressId,int isAutoPt);


}
